﻿Public Class frmQuanLyTaiKhoan
    Dim startime As DateTime

    Private Sub frmQuanLyTaiKhoan_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Dim dt As DataTable = TaiKhoanDAO.LoadTaiKhoan()
        dtgvTaiKhoan.DataSource = dt
        dtgvTaiKhoan.Columns(0).HeaderText = "Tài khoản"
        dtgvTaiKhoan.Columns(1).HeaderText = "Mật khẩu"
        dtgvTaiKhoan.Columns(2).HeaderText = "Họ tên"
        dtgvTaiKhoan.Columns(3).HeaderText = "Địa chỉ"
        dtgvTaiKhoan.Columns(4).HeaderText = "Số CMND"
        dtgvTaiKhoan.Columns(5).HeaderText = "Giới tính"
        dtgvTaiKhoan.Columns(6).HeaderText = "Loại"

    End Sub

    Private Sub BtnThem_Click(sender As System.Object, e As System.EventArgs) Handles BtnThem.Click
        Dim frm As frmTaiKhoan = New frmTaiKhoan()
        frm.ShowDialog()
        frm.Dispose()
    End Sub

    Private Sub btnThoat_Click(sender As System.Object, e As System.EventArgs) Handles btnThoat.Click
        If (MessageBox.Show("Bạn có chắc chắn thoát không?", "Thoát", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes) Then
            Me.Close()
        End If
    End Sub

    Private Sub BtnXoa_Click(sender As System.Object, e As System.EventArgs) Handles BtnXoa.Click
        Dim xoa As String
        xoa = dtgvTaiKhoan.Rows(dtgvTaiKhoan.CurrentCell.RowIndex).Cells(0).Value

        Dim tk As TaiKhoan = New TaiKhoan()
        tk.m_strTenDangNhap = xoa.ToString()
        TaiKhoanDAO.XoaTK(tk)
        MessageBox.Show("Xóa thành công!")

        Dim dt As DataTable = TaiKhoanDAO.LoadTaiKhoan()
        dtgvTaiKhoan.DataSource = dt

    End Sub

    Private Sub BtnSua_Click(sender As System.Object, e As System.EventArgs) Handles BtnSua.Click
        Dim frm As frmCapNhatTK = New frmCapNhatTK()
        frm.lbtendangnhap.Text = dtgvTaiKhoan.Rows(dtgvTaiKhoan.CurrentCell.RowIndex).Cells(0).Value.ToString()
        frm.txtMatKhau.Text = dtgvTaiKhoan.Rows(dtgvTaiKhoan.CurrentCell.RowIndex).Cells(1).Value.ToString()
        frm.txtHoTen.Text = dtgvTaiKhoan.Rows(dtgvTaiKhoan.CurrentCell.RowIndex).Cells(2).Value.ToString()
        frm.txtDiaChi.Text = dtgvTaiKhoan.Rows(dtgvTaiKhoan.CurrentCell.RowIndex).Cells(3).Value.ToString()
        frm.txtCMND.Text = dtgvTaiKhoan.Rows(dtgvTaiKhoan.CurrentCell.RowIndex).Cells(4).Value.ToString()
        frm.cbxGioiTinh.Text = dtgvTaiKhoan.Rows(dtgvTaiKhoan.CurrentCell.RowIndex).Cells(5).Value.ToString()
        frm.cbxLoaiTaiKhoan.Text = dtgvTaiKhoan.Rows(dtgvTaiKhoan.CurrentCell.RowIndex).Cells(6).Value.ToString()
        frm.Show()

    End Sub

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Dim dt As DataTable = TaiKhoanDAO.LoadTaiKhoan()
        dtgvTaiKhoan.DataSource = dt
    End Sub
End Class